local DTMgr = {
	fullJsonCacheList = {},
	fullJsonCacheListQueue = {},
	fullJsonCacheSaveNum = 200,--保存数量
	earliestIndex = 1,--最早插入的索引
}
function DTMgr.Get(name)
	return DTMgr.fullJsonCacheList[name]
end
function DTMgr.Insert(name,jsonTB)
	local this = DTMgr
	if #this.fullJsonCacheListQueue >= this.fullJsonCacheSaveNum then
		--print("Insert name "..name)
		local oldName = this.fullJsonCacheListQueue[this.earliestIndex]
		this.fullJsonCacheListQueue[this.earliestIndex] = name
		this.earliestIndex = (this.earliestIndex ) % this.fullJsonCacheSaveNum + 1
		this.fullJsonCacheList[oldName] = nil
		this.fullJsonCacheList[name] = jsonTB
	else
		table.insert(this.fullJsonCacheListQueue,name)
		this.fullJsonCacheList[name] = jsonTB
	end
end
--输出日志--
function log(str)
    Util.Log(str);
end

--错误日志--
function logError(str) 
	Util.LogError(debug.traceback(tostring(str), 3));
end

--警告日志--
function logWarn(str) 
	Util.LogWarning(str);
end

local json = require "cjson"
local json_safe = require "cjson.safe"
function decodeJsonStrToTable(jonsonStr,isNew)
	if jonsonStr == nil or jonsonStr == "" then return nil end
	local tt = type(jonsonStr)
	-- 已经解析过了
	if jonsonStr ~= nil and tt == "table" then
		return jonsonStr
	end
	if jonsonStr ~= nil and tt == "number" then
		return jonsonStr
	end
	if isNew then
		return json_safe.decode(jonsonStr)
	end
	local tempV = DTMgr.Get(jonsonStr)
	if tempV == nil then
		tempV = json_safe.decode(jonsonStr);
		if tempV ~= nil then
			DTMgr.Insert(jonsonStr,tempV)
		end
	end

	return tempV
end

function getJsonStr(tbl)
	json.encode_sparse_array(true);
	local result = json.encode(tbl);

	return result;
end

--分割字符串 1.待分割字符串 2.分隔符,3 table 列表
function string_split(str, split_char, tbList)
	local sub_str_tab = tbList or {};
	while (true) do
		local pos = string.find(str, split_char);
		if (not pos) then
			sub_str_tab[#sub_str_tab + 1] = str;
			break ;
		end
		local sub_str = string.sub(str, 1, pos - 1);
		sub_str_tab[#sub_str_tab + 1] = sub_str;
		str = string.sub(str, pos + 1, #str);
	end

	return sub_str_tab;

end

function string.IsEmpty(str)
	return str == nil or str == ""
end
function string.Contains(str,sub)
	return string.find(str,sub)
end
---返回 00:00
function GetMinuteSecondStr(second)
	if second <= 0 then
		return "00:00"
	end
	local minute =  math.floor(second /60)
	second = second % 60
	return string.format("%02d:%02d",minute,second)
end
--根据playerId存
function SetPlayerPrefs(key, value)
	local roleId = 0
	local serverId = 0
	PlayerPrefs.SetString(roleId .. serverId .. key,tostring(value))
end
function GetPlayerPrefs(key)
	local roleId = 0
	local serverId = 0
	return PlayerPrefs.GetString(roleId .. serverId ..key,"")
end
--查找对象--
function find(str)
	return GameObject.Find(str);
end

function destroy(obj)
	GameObject.Destroy(obj);
end
---@return GComponent
function newGComponent(packName,objName)
	return UIPackage.CreateObject(packName, objName);
end

function showUI(panelName, ...)
	local cfg = PanelConfig[panelName]
	if cfg == nil then
		logError("找不到panelName in PanelConfig :"..tostring(panelName))
		return
	end
	local ui = require(cfg.script)
	if ui ~= nil and ui.Init then
		ui:Init(...)
	end
	panelMgr:ShowUI( cfg.package,cfg.fui,ui)
	panelMgr:SetFullScreen(cfg.fui,cfg.isFullScreen or false)
end

--关闭UI
function closeUI(panelName)
	local cfg = PanelConfig[panelName]
	panelMgr:CloseUI(cfg.package,cfg.fui, true)
end

function table.clear(tb)
	for k,v in pairs(tb) do
		tb[k] = nil
	end
end
function table.CopyDicToArray(srcTB,dstArray)
	for k,v in pairs(srcTB) do
		table.insert(dstArray,v)
	end
end
function addTable(table1,table2)
	for i, v in pairs(table2) do
		table1[i] = v;

	end
end
function table.getn(table)
	--table key非递增情况下使用
	if table ~= nil then
		local index = 0
		for k, v in pairs(table) do
			index = index + 1
		end
		return index
	end
	return 0
end
function table.ContainsValue(tb,value)
	for k,v in pairs(tb) do
		if v == value then
			return true
		end
	end
	return false
end
function table.RemoveValue(tb,value,isArray)
	for k,v in pairs(tb) do
		if v == value then
			if isArray then
				table.remove(tb,k)
			else
				tb[k] = nil
			end
			break
		end
	end
end
-- 重写全局报错处理
__G__TRACKBACK__ = function(msg)
	local msg = debug.traceback(msg, 3)
	Util.LogError(msg);
	return msg
end